<?php
/**
 * 主播管理员控制器
 */

namespace app\web\controller;


use think\Controller;
use think\Env;

class CollectCards extends Controller
{
    /**
     * 春节集卡活动，跳转到taro web里
     */
    public function index()
    {
        $headers = request()->header();
        $h = input('h/d', 0);

        $uen = input('uen/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送uen
        $text = input('text/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送字

        $url_wap_pre = Env::get('host.wap_domain') . '/zhunle_wap_collect_cards';

        if (isset($headers['access-token']))
        {//在App里
            if ($headers['app-type'] === 'ios')
            {
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //ios 直接redirect即可
                $this->redirect($url);
            } else
            {//android 使用跳转
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //方法1：使用iframe【问题太多】
                $this->assign('url', $url);
                return $this->fetch('index');

                //方法2：把项目copy到zhunle_api里【还得改路由，并且部署太麻烦先不考虑】
            }
        } else
        {//在App外，直接redirect
            $url = $url_wap_pre . '?is_in_app=0' . '&uen=' . $uen . '&text=' . $text;
            $this->redirect($url);
        }


    }

    /**
     * 2022五一集卡活动，跳转到taro web里
     */
    public function may_day()
    {
        $headers = request()->header();
        $h = input('h/d', 0);

        $uen = input('uen/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送uen
        $text = input('text/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送字

        $url_wap_pre = Env::get('host.wap_domain') . '/zhunle_wap_collect_cards_may_day';

        if (isset($headers['access-token']))
        {//在App里
            if ($headers['app-type'] === 'ios')
            {
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //ios 直接redirect即可
                $this->redirect($url);
            } else
            {//android 使用跳转
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //方法1：使用iframe【问题太多】
                $this->assign('url', $url);
                return $this->fetch('index');

                //方法2：把项目copy到zhunle_api里【还得改路由，并且部署太麻烦先不考虑】
            }
        } else
        {//在App外，直接redirect
            $url = $url_wap_pre . '?is_in_app=0' . '&uen=' . $uen . '&text=' . $text;
            $this->redirect($url);
        }
    }


    /**
     * 2023春节集卡活动，跳转到taro web里
     */
    public function index_2023()
    {
        $headers = request()->header();
        $h = input('h/d', 0);

        $uen = input('uen/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送uen
        $text = input('text/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送字

        $url_wap_pre = Env::get('host.wap_domain') . '/zhunle_wap_2023_collect_cards';

        if (isset($headers['access-token']))
        {//在App里
            if ($headers['app-type'] === 'ios')
            {
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //ios 直接redirect即可
                $this->redirect($url);
            } else
            {//android 使用跳转
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //方法1：使用iframe【问题太多】
                $this->assign('url', $url);
                return $this->fetch('index');

                //方法2：把项目copy到zhunle_api里【还得改路由，并且部署太麻烦先不考虑】
            }
        } else
        {//在App外，直接redirect
            $url = $url_wap_pre . '?is_in_app=0' . '&uen=' . $uen . '&text=' . $text;
            $this->redirect($url);
        }


    }


    /**
     * 2024春节集卡活动，跳转到taro web里
     */
    public function index_2024()
    {
        $headers = request()->header();
        $h = input('h/d', 0);

        $uen = input('uen/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送uen
        $text = input('text/s', '');//用户点击分享的h5，通过魔链跳转到App里的，赠送字

        $url_wap_pre = Env::get('host.wap_domain') . '/zhunle_wap_2024_collect_cards';

        if (isset($headers['access-token']))
        {//在App里
            if ($headers['app-type'] === 'ios')
            {
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //ios 直接redirect即可
                $this->redirect($url);
            } else
            {//android 使用跳转
                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&uen=' . $uen . '&text=' . $text;
                //方法1：使用iframe【问题太多】
                $this->assign('url', $url);
                return $this->fetch('index_2024');

                //方法2：把项目copy到zhunle_api里【还得改路由，并且部署太麻烦先不考虑】
            }
        } else
        {//在App外，直接redirect
            $url = $url_wap_pre . '?is_in_app=0' . '&uen=' . $uen . '&text=' . $text;
            $this->redirect($url);
        }


    }


    /**
     * 准了app内置的 属性卡片、四象卡片、使用说明书，跳转到taro web里
     */
    public function card()
    {
        $headers = request()->header();
        $h = input('h/d', 0);
        $page = input('page/s', '');//页面类型[astro_card:属性卡片;attr_card:四象卡片;instruction_card:使用说明书]
        $rid = input('rid/d', 0);

        $url_wap_pre = Env::get('host.wap_domain') . '/zhunle_wap_card';

        if (isset($headers['access-token']))
        {//在App里
//            if ($headers['app-type'] === 'ios')
//            {
            $url = $url_wap_pre . '/common_list?' . 'app_type=' . urlencode($headers['app-type']) . '&did=' . urlencode($headers['did']) . '&model=' . urlencode($headers['model']) . '&sign=' . urlencode($headers['sign']) . '&time=' . urlencode($headers['time']) . '&version=' . urlencode($headers['version']) . '&phone_version=' . urlencode($headers['phone-version']) . '&h=' . $h . '&is_in_app=1' . '&page=' . $page . '&rid=' . $rid . '&token=' . urlencode($headers['access-token']);
            //ios 直接redirect即可
            $this->redirect($url);
//            } else
//            {//android 使用跳转
//                $url = $url_wap_pre . '?' . 'token=' . $headers['access-token'] . '&app_type=' . $headers['app-type'] . '&did=' . $headers['did'] . '&model=' . $headers['model'] . '&sign=' . $headers['sign'] . '&time=' . $headers['time'] . '&version=' . $headers['version'] . '&phone_version=' . $headers['phone-version'] . '&h=' . $h . '&is_in_app=1' . '&page=' . $page . '&rid=' . $rid;
//                //方法1：使用iframe【问题太多】
//                $this->assign('url', $url);
//                return $this->fetch('index_card');
//
//                //方法2：把项目copy到zhunle_api里【还得改路由，并且部署太麻烦先不考虑】
//            }
        } else
        {//在App外，直接redirect app下载页
            $link = Env::get('host.domain') . '/web/collect_cards/card?need_auth=1&zhunle_not_show_nav=1&page=' . $page . '&rid=' . $rid;
            $url = 'https://applink-zhunle.goddessxzns.com?app=zhunle&target=link&link=' . urlencode($link);
            $this->redirect($url);
        }


    }
}
